package cn.itcast.service.impl;

import cn.itcast.dao.UserDao;
import cn.itcast.dao.impl.UserDaoImpl;
import cn.itcast.domain.User;
import cn.itcast.exception.UserExistException;
import cn.itcast.utils.ServiceUtils;

public class BusinessServiceImpl {
	private UserDao dao= new UserDaoImpl();
	
	public void register(User user) throws UserExistException {
		boolean b = dao.find(user.getUsername());
		if(b) {
			throw new UserExistException();
		}
		else {
			user.setPassword(ServiceUtils.md5(user.getPassword()));
			dao.add(user);
			
		}
		
	}
	
	public User login(String username, String password) {
		password = ServiceUtils.md5(password);
		return dao.find(username, password);
		
	}
}
